package chapter04

import scala.collection.mutable

/**
 * @program lu-scala01
 * @description:  可变Map
 *  -- 无序
 * @author: zhanglu
 * @create: 2022-04-08 22:29:00
 */
object Lu09_MutableMap {

  def main(args: Array[String]): Unit = {
    val m1: mutable.Map[String, Int] = mutable.Map("a" -> 1, "b" -> 2)
    println(m1)
    println(m1.getClass)

    //添加元素

    m1.put("c", 3)
    println(m1)

    m1 += (("d", 4))
    println(m1)

    println("===========")

    //删除元素
    m1.remove("d")
    println(m1)

    m1 -= "c"
    println(m1)

    //修改元素
    m1.put("c", 4)
    m1.put("c", 3)
    println(m1)

    //合并map
    val m2: mutable.Map[String, Int] = mutable.Map("aa" -> 11, "b" -> 4)
    m1 ++= m2
    println(m1)



  }

}
